package binary_tree

import (
	"fmt"
	"strconv"
)

type Node struct {
	Val int
	Left *Node
	Right *Node
}


func PrintBinaryTree (root *Node) {
	if root == nil {return}
	PrintInOrder(root, 0, "H", 17)
}

func PrintInOrder(node *Node, layer int, to string, formatLen int){
	if node == nil { return }
	PrintInOrder(node.Right, layer+1, "V", formatLen)
	val := to + strconv.Itoa(node.Val) + to
	leftLen := (formatLen-len(val))/2
	rightLen := formatLen-leftLen
	fmt.Println(GetSpace(layer*17) + GetSpace(leftLen) + val + GetSpace(rightLen))
	PrintInOrder(node.Left, layer+1, "^", formatLen)
}

func GetSpace(num int) string {
	ans := ""
	for i:=0; i<num; i++ {
		ans += " "
	}
	return ans
}
